<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.ok{
				color: green;
			}
			.error{
				color: red;
			}
		</style>
		<script type="text/javascript">
			function checkName() {
				var name = document.getElementById("name").value;
				var span = document.getElementById("nameMsg");
				var reg = /^\w{5,10}$/;
				if (name.match(reg)) {
					span.className = "ok";
				} else {
					span.className = "error";
				}
			}
			
			function checkEmail() {
				var emial = document.getElementById("email").value;
				var span = document.getElementById("emailMsg");
				// 63468gdf@gmail.com.cn
				var reg = /^[a-zA-Z0-9_-]+@\w+(\.[a-zA-Z0-9]+)+$/;
				if (emial.match(reg)) {
					span.className = "ok";
				} else {
					span.className = "error";
				}
			}
		</script>
	</head>
	<body>
		名字： <input type="text" id="name" onblur="checkName()" />
		<span id="nameMsg">5-10位字母、数字、下划线</span>
		<br/>
		邮箱： <input type="text" id="email" onblur="checkEmail()" />
		<span id="emailMsg">必须符合邮箱的格式</span>
	</body>
</html>
